import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import vuexpersist from "vuex-persist";

export default new Vuex.Store({
  state: {
    page:0,
    size:3,
    i:0,
    shopping:[]

  },
  mutations: {
    asd(state){
      state.i++
      if(state.i==0){

      }else{
        if(state.i<=8){
          state.page+=3
          state.size+=3
        }else{
          state.page=0
          state.size=3
          state.i=0
        }
      }
    
     
      

    },
    add(state,c){
      console.log(c);

      var cp=false
      state.shopping.forEach(res=>{
        if(res.id==c.id){
          res.num++
          cp=true

        }
      })

      if(cp==false){
        Vue.set(c,'num',1)
        state.shopping.push(c)
      }




    },
    remove(state,i){
      state.shopping.splice(i,1)
    }
  },
  actions: {
  },
  modules: {
  },
  plugins:[
    new vuexpersist({
      storage:window.localStorage
    }).plugin
  ]
})
